**************************************************************************************************
*** This do file creates the spatial-x variables for 
*** Authors in alphabetical order: Denise Laroze, Eric Neumayer, Thomas Pluemper.
*** Covid-19 does not Stop at Open Borders: Spatial Contagion among Local Authority Districts During England’s First Wave 
*** Social Science & Medicine, Volume 270, February 2021, 113655, https://doi.org/10.1016/j.socscimed.2020.113655. 

*** This is for illustration only. The spatial-x variables are already contained in the replication dataset
							
**************************************************************************************************
**************************************************************************************************
/* Note: You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 
/* You must have Stata version 13 or higher installed													*/
**************************************************************************************************
*/

drop _all
clear matrix
clear mata


capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o) /* checks whether outreg2 is installed 		*/

capture net install spmon, from(http://fmwww.bc.edu/RePEc/bocode/s) /* checks whether spmon is installed 		*/

***********************************************************************************
local DIR = "D:\Research\Health for all database\United Kingdom\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************


use "Article for Social Science & Medicine (C19) spatial-x source data.dta", clear


* population
spmon  p_over65_k, w(comm_tot_fraction) i(code_i) k(code_k) sename(p_over65_comm) filename (p_over65_comm)  time(week)
spmon  p_over65_k, w(contiguous) i(code_i) k(code_k) sename(p_over65_cont) filename (p_over65_cont)  time(week)

spmon  p_rural_k, w(comm_tot_fraction) i(code_i) k(code_k) sename(p_rural_comm) filename (p_rural_comm)  time(week)
spmon  p_rural_k, w(contiguous) i(code_i) k(code_k) sename(p_rural_cont) filename (p_rural_cont)  time(week)

spmon  IMD_10pc_deprived_k, w(comm_tot_fraction) i(code_i) k(code_k) sename(IMD_10pc_deprived_comm) filename (IMD_10pc_deprived_comm)  time(week)
spmon  IMD_10pc_deprived_k, w(contiguous) i(code_i) k(code_k) sename(IMD_10pc_deprived_cont) filename (IMD_10pc_deprived_cont)  time(week)

spmon  mean_income_2019_k, w(comm_tot_fraction) i(code_i) k(code_k) sename(mean_income_2019_comm) filename (mean_income_2019_comm)  time(week)
spmon  mean_income_2019_k, w(contiguous) i(code_i) k(code_k) sename(mean_income_2019_cont) filename (mean_income_2019_cont)  time(week)

spmon  p_ethn_BAME_percent_k, w(comm_tot_fraction) i(code_i) k(code_k) sename(p_ethn_BAME_comm) filename (p_ethn_BAME_comm)  time(week)
spmon  p_ethn_BAME_percent_k, w(contiguous) i(code_i) k(code_k) sename(p_ethn_BAME_cont) filename (p_ethn_BAME_cont)  time(week)


use "mean_income_2019_cont", clear
mmerge week code_i using "mean_income_2019_comm"

mmerge week code_i using "IMD_10pc_deprived_comm"
mmerge week code_i using "IMD_10pc_deprived_cont"

mmerge week code_i using "p_rural_comm"
mmerge week code_i using "p_rural_cont"

mmerge week code_i using "IMD_10pc_deprived_comm"
mmerge week code_i using "IMD_10pc_deprived_cont"


mmerge week code_i using "p_ethn_BAME_comm"
mmerge week code_i using "p_ethn_BAME_cont"

mmerge week code_i using "p_over65_comm"
mmerge week code_i using "p_over65_cont"

drop _merge 

decode code_i, gen(code_i_string)


ren week Week_number

save "spatial_x.dta", replace


